<script language="javascript" type="text/javascript">
    $(window).scroll(
    function()
    {
        scrollTop = $(window).scrollTop();
        docHeight = getDocHeight();
        winHeight = getWinHeight();
        scrolltop20 = Math.round((getDocHeight() - getWinHeight())*0.9);
        result = getDocHeight() - getWinHeight();
		
        console.log('Top Scroll: '+ scrollTop +' || Win Height: '+ winHeight +' || Doc Height: '+ docHeight+' || scrolltop20: '+scrolltop20+' || result :'+ result );
	
        if($(window).scrollTop() >= scrolltop20)
        {
            if(killScroll == false) 
            {
                killScroll = true;
				
                $('#loading').show();
                $('#loadding-text').show();			
                $('#loading').html('<img src="images/loading.gif" alt="" width="150" height="13" />');

                if($("li:last").data('ctype') == 'club')
                {
                    lastPostFunc('club');
                }
                setTimeout(function(){killScroll = false},500);	
            }
        }
    }
); 

    function searchClub()
    {
        if($('#club_search').val() != '')
        {	
            $('#fromSearchClub').submit();
        }
        else
        {
            $('#clubAlert').popup('open');
            setTimeout(function(){$('#clubAlert').popup('close'); $('#club_search').focus()},1000);
        }
    }

</script>  

<!-- Start of news page -->
<div data-role="page" id="club">
    <div data-role="header">
        <h1>ชมรม</h1>
        <a rel="external" id="link_web" href="?q=home" data-icon="back" data-iconpos="right">กลับ</a> 
        <a href="#from_clubSearch" data-role="button" data-icon="search" data-iconpos="right" data-transition="slidedown" data-rel="dialog" >ค้นหา</a>      
    </div><!-- /header -->
    <div data-role="content">	
        <ul data-role="listview">
            <li data-role="list-divider" id="listDivider_step">
                <a rel="external" href="?q=home">หน้าแรก</a>&nbsp;&nbsp;>>&nbsp;&nbsp;<a rel="external" href="?q=club">ชมรม</a>
            </li>
            <?php
            $res = $db->select_query('SELECT * FROM clubs  ORDER BY id DESC LIMIT 20');
            while($arr = $db->fetch($res))
            {
                $countPost = $db->num_rows('clubs_post', 'post_id', 'club_id = ' . $arr['id'] . '');
                ?>
                <li data-ctype="club" id="club_<?php echo $arr['id']; ?>" last_id="<?php echo $arr['id']; ?>">
                    <a rel="external" href="?q=clubListDetail&cId=<?php echo $arr['id']; ?>">
                        <img src="<?php echo $arr['tn_part']; ?>" alt="" width="80" height="80" />
                        <h3><?php echo $arr['name']; ?></h3>
                        <p><?php echo $arr['headline']; ?></p>
                        <span class="ui-li-count ui-btn-up-c ui-btn-corner-all"><?php echo $countPost; ?></span>
                    </a> 
                </li>
                <?php
            }
            ?>
        </ul> 
        <div id="loadding-text" style="clear:both;">&nbsp;&nbsp;</div>       
        <div id="loading" align="center"><img src="images/loading.gif" alt="" width="150" height="13" /></div>       
    </div><!-- /content -->
    <div data-role="footer" >
        <h4>Version 1.0 Beta</h4>
        <a id="link_web" href="http://www.mocyc.com" data-icon="refresh" data-iconpos="right" class="ui-btn-right">แบบปกติ</a>
    </div><!-- /footer -->
</div><!-- /page -->

<!-- From from_clubSearch -->
<div data-role="page" id="from_clubSearch">
    <div data-role="header">
        <h1>ค้นหา</h1>
    </div>
    <div data-role="content">
        <form id="fromSearchClub" name="fromSearchClub" method="get" data-ajax="false">
            <input name="q" type="hidden" value="clubSearch" />
            คำค้นหา
            <input type="search" name="club_search" id="club_search" value=""  />    
            <label>&nbsp;</label><br /> 
            <input id="search" name="search" type="button" value="ค้นหา" onclick="searchClub();" />
        </form>

        <div data-role="popup" id="clubAlert">
            <p>กรุณาระบุ "คำค้นหา" ที่ต้องการ<p>
        </div>  
    </div>
</div>
<!-- End From from_clubSearch -->